home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0186.arc
/
ARTINT2.LTG
< prev
next >
Wrap
Text File
|
1986-12-20
|
768b
|
18 lines
Listing 2
Pattern Matcher in Lisp
(DEFUN MATCH (LAMBDA (P E)
(COND ((OR (EQUAL P E) ;Identical things match
(MEMBER P '(? *))) T) ;? and * match anything
((OR (ATOM P) (ATOM E)) NIL) ;No match now if not both lists
((EQUAL (CAR P) '*) ;If pattern starts with *, we
(OR (MATCH (CDR P) (CDR E)) ; match if both tails match or
(MATCH P (CDR E)))) ; if P (with *) matches tail of E
(T (AND (MATCH (CAR P) (CAR E)) ;Else we match if heads match
(MATCH (CDR P) (CDR E)))))) ; and tails match